<template>
  <ul>
    <li v-for="item in listData" :key="item.name">
      <i class="iconfont" :class="item.icon"></i>
      <div>
        <p>{{ item.name }}</p>
        <span>{{ item.count }}</span>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  props: {
    sonData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      listData: [
        {
          name: '今日订单',
          count: 0,
          icon: 'icon-dingdan',
          flag: 'today_order_num'
        },
        {
          name: '今日销售额',
          count: 0,
          icon: 'icon-jinexianxing',
          flag: 'today_sale'
        },
        {
          name: '总订单',
          count: 0,
          icon: 'icon-renwu',
          flag: 'total_order_num'
        },
        {
          name: '总销售额',
          count: 0,
          icon: 'icon-Dollar',
          flag: 'total_sale'
        }
      ]
    }
  },
  watch: {
    sonData: {
      handler() {
        this.listData.forEach((item) => {
          item.count = this.sonData[item.flag]
        })
      },
      deep: true
    }
  }
}
</script>

<style lang="less" scoped>
ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;

  li {
    flex: 0 0 22%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ccc;
    padding: 15px;
    box-sizing: border-box;
    border-radius: 6px;
    color: #fff;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.03);

    i {
      font-size: 35px;
      color: #fff;
    }

    div {
      text-align: right;
    }

    p {
      margin: 0;
      font-size: 14px;
      color: #eee;
      text-align: right;
      margin-bottom: 8px;
    }

    span {
      font-weight: 700;
      font-size: 18px;
    }

    &:nth-of-type(1) {
      background: linear-gradient(90deg, #03a9f4, #2196f3);
      i {
        color: #00fff3;
      }
    }
    &:nth-of-type(2) {
      background: linear-gradient(90deg, #ff9800, #ff5722);
    }
    &:nth-of-type(3) {
      background: linear-gradient(90deg, #9c27b0, #673ab7);
      i {
        color: #ffeb3b;
      }
    }
    &:nth-of-type(4) {
      background: linear-gradient(90deg, #e91e63, #f44336);
      i {
        color: #91ff00;
      }
    }
  }
}
</style>
